﻿using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace TI_BLE_HCI_ClientLib.Tests
{
    internal class TestHelpers
    {
        public static byte[] StringToByteArray(string spacedhex)
        {
            string hex = Regex.Replace(spacedhex, @"\s", "");
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }

        public static byte[] StringWithColonsToByteArray(string hexstring)
        {
            string hex = Regex.Replace(hexstring, @":", "");
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }

        public static byte[] StringWithColonsToByteArrayReversed(string hexstring)
        {
            string hex = Regex.Replace(hexstring, @":", "");
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .Reverse()
                             .ToArray();
        }
    }
}